home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Fish Fillets / script / pavement / code.lua next >
Text File  |  2005-07-16  |  16KB  |  430 lines

  1.  
  2. -- -----------------------------------------------------------------
  3. -- Init
  4. -- -----------------------------------------------------------------
  5. local function prog_init()
  6.     initModels()
  7.     sound_playMusic("music/rybky02.ogg")
  8.     local pokus = getRestartCount()
  9.  
  10.  
  11.     -- -------------------------------------------------------------
  12.     local function prog_init_room()
  13.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  14.  
  15.         room.pocetrad = 0
  16.         room.kdydalsi = random(200) + 200
  17.         room.posluvod = random(5)
  18.         room.konce = {}
  19.  
  20.         return function()
  21.             if no_dialog() and isReady(small) and isReady(big) then
  22.                 if room.kdydalsi > 0 then
  23.                     room.kdydalsi = room.kdydalsi - 1
  24.                 end
  25.                 if room.kdydalsi == 0 then
  26.                     room.pocetrad = room.pocetrad + 1
  27.                     room.kdydalsi = (random(200) + 100) * (room.pocetrad + 2)
  28.                     pom1 = random(4)
  29.                     if pom1 == room.posluvod then
  30.                         pom1 = 4
  31.                     end
  32.                     room.posluvod = pom1
  33.                     vladce:planDialog(20, "dir-hs-uvod"..pom1)
  34.                     if countPairs(room.konce) < 9 then
  35.                         repeat
  36.                             pom1 = random(9)
  37.                         until not room.konce[pom1]
  38.                     else
  39.                         room.konce = {}
  40.                         pom1 = random(9)
  41.                     end
  42.                     room.konce[pom1] = true
  43.                     vladce:planDialog(0, "dir-hs-konec"..pom1)
  44.                     if room.pocetrad >= 5 then
  45.                         pom1 = random(6)
  46.                     else
  47.                         pom1 = random(room.pocetrad + 1)
  48.                     end
  49.                     adddel(random(10))
  50.                     if pom1 > 0 then
  51.                         switch(random(2)){
  52.                             [0] = function()
  53.                                 addm(0, "dir-m-rada"..(pom1 - 1))
  54.                             end,
  55.                             [1] = function()
  56.                                 addv(0, "dir-v-rada"..(pom1 - 1))
  57.                             end,
  58.                         }
  59.                     end
  60.                 end
  61.             end
  62.         end
  63.     end
  64.  
  65.     -- -------------------------------------------------------------
  66.     local function prog_init_vladce()
  67.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  68.  
  69.         vladce.ksichty = 0
  70.         vladce.faze = 0
  71.  
  72.         return function()
  73.             vladce.afaze = vladce.afaze + 1
  74.             local anim_table = {
  75.                 [0] = function()
  76.                     if vladce:isTalking() then
  77.                         vladce.ksichty = random(4) + 1
  78.                     end
  79.                 end,
  80.                 [1] = function()
  81.                     if math.mod(game_getCycles(), 2) == 0 then
  82.                         if vladce:isTalking() then
  83.                             pom1 = random(3)
  84.                         else
  85.                             pom1 = 3
  86.                         end
  87.                         switch(vladce.ksichty){
  88.                             [1] = function()
  89.                                 switch(pom1){
  90.                                     [0] = function()
  91.                                         vladce.afaze = 1
  92.                                     end,
  93.                                     [1] = function()
  94.                                         vladce.afaze = 15
  95.                                     end,
  96.                                     [2] = function()
  97.                                         vladce.afaze = 18
  98.                                     end,
  99.                                     [3] = function()
  100.                                         vladce.afaze = 1
  101.                                     end,
  102.                                 }
  103.                             end,
  104.                             [2] = function()
  105.                                 switch(pom1){
  106.                                     [0] = function()
  107.                                         vladce.afaze = 4
  108.                                     end,
  109.                                     [1] = function()
  110.                                         vladce.afaze = 16
  111.                                     end,
  112.                                     [2] = function()
  113.                                         vladce.afaze = 20
  114.                                     end,
  115.                                     [3] = function()
  116.                                         vladce.afaze = 1
  117.                                     end,
  118.                                 }
  119.                             end,
  120.                             [3] = function()
  121.                                 switch(pom1){
  122.                                     [0] = function()
  123.                                         vladce.afaze = 14
  124.                                     end,
  125.                                     [1] = function()
  126.                                         vladce.afaze = 17
  127.                                     end,
  128.                                     [2] = function()
  129.                                         vladce.afaze = 19
  130.                                     end,
  131.                                     [3] = function()
  132.                                         vladce.afaze = 14
  133.                                     end,
  134.                                 }
  135.                             end,
  136.                             [4] = function()
  137.                                 switch(pom1){
  138.                                     [0] = function()
  139.                                         vladce.afaze = 6
  140.                                     end,
  141.                                     [1] = function()
  142.                                         vladce.afaze = 15
  143.                                     end,
  144.                                     [2] = function()
  145.                                         vladce.afaze = 18
  146.                                     end,
  147.                                     [3] = function()
  148.                                         vladce.afaze = 11
  149.                                     end,
  150.                                 }
  151.                             end,
  152.                         }
  153.                         if pom1 == 3 then
  154.                             vladce.ksichty = 0
  155.                         end
  156.                     end
  157.                 end,
  158.                 [10] = function()
  159.                     vladce.faze = vladce.faze + 1
  160.                     switch(vladce.faze){
  161.                         [1] = function()
  162.                             vladce.afaze = 5
  163.                         end,
  164.                         [2] = function()
  165.                             vladce.afaze = 9
  166.                         end,
  167.                         [3] = function()
  168.                             vladce.afaze = 10
  169.                         end,
  170.                         [4] = function()
  171.                             vladce.ksichty = 0
  172.                         end,
  173.                     }
  174.                 end,
  175.                 [11] = function()
  176.                     vladce.faze = vladce.faze + 1
  177.                     switch(vladce.faze){
  178.                         [1] = function()
  179.                             vladce.afaze = 9
  180.                         end,
  181.                         [2] = function()
  182.                             vladce.afaze = 5
  183.                         end,
  184.                         [3] = function()
  185.                             vladce.afaze = 1
  186.                         end,
  187.                         [4] = function()
  188.                             vladce.ksichty = 0
  189.                         end,
  190.                     }
  191.                 end,
  192.                 [12] = function()
  193.                     vladce.faze = vladce.faze + 1
  194.                     switch(vladce.faze){
  195.                         [1] = function()
  196.                             vladce.afaze = 6
  197.                         end,
  198.                         [2] = function()
  199.                             vladce.afaze = 7
  200.                         end,
  201.                         [3] = function()
  202.                             vladce.afaze = 11
  203.                         end,
  204.                         [4] = function()
  205.                             vladce.ksichty = 0
  206.                         end,
  207.                     }
  208.                 end,
  209.                 [13] = function()
  210.                     vladce.faze = vladce.faze + 1
  211.                     switch(vladce.faze){
  212.                         [1] = function()
  213.                             vladce.afaze = 7
  214.                         end,
  215.                         [2] = function()
  216.                             vladce.afaze = 6
  217.                         end,
  218.                         [3] = function()
  219.                             vladce.afaze = 1
  220.                         end,
  221.                         [4] = function()
  222.                             vladce.ksichty = 0
  223.                         end,
  224.                     }
  225.                 end,
  226.                 [14] = function()
  227.                     vladce.faze = vladce.faze + 1
  228.                     switch(vladce.faze){
  229.                         [1] = function()
  230.                             vladce.afaze = 9
  231.                         end,
  232.                         [2] = function()
  233.                             vladce.afaze = 5
  234.                         end,
  235.                         [3] = function()
  236.                             vladce.afaze = 14
  237.                         end,
  238.                         [4] = function()
  239.                             vladce.ksichty = 0
  240.                         end,
  241.                     }
  242.                 end,
  243.                 [20] = function()
  244.                     vladce.faze = vladce.faze + 1
  245.                     switch(vladce.faze){
  246.                         [1] = function()
  247.                             vladce.afaze = 6
  248.                         end,
  249.                         [2] = function()
  250.                             vladce.afaze = 8
  251.                         end,
  252.                         [3] = function()
  253.                             vladce.afaze = 8
  254.                         end,
  255.                         [4] = function()
  256.                             vladce.afaze = 6
  257.                         end,
  258.                         [5] = function()
  259.                             vladce.ksichty = 0
  260.                         end,
  261.                     }
  262.                 end,
  263.                 [21] = function()
  264.                     vladce.faze = vladce.faze + 1
  265.                     switch(vladce.faze){
  266.                         [2] = function()
  267.                             vladce.afaze = 4
  268.                         end,
  269.                         [6] = function()
  270.                             vladce.ksichty = 0
  271.                         end,
  272.                         default = function()
  273.                             if isIn(vladce.faze, {1, 3, 5}) then
  274.                                 vladce.afaze = 1
  275.                             end
  276.                         end,
  277.                     }
  278.                 end,
  279.                 [22] = function()
  280.                     vladce.faze = vladce.faze + 1
  281.                     switch(vladce.faze){
  282.                         [2] = function()
  283.                             vladce.afaze = 12
  284.                         end,
  285.                         [6] = function()
  286.                             vladce.ksichty = 0
  287.                         end,
  288.                         default = function()
  289.                             if isIn(vladce.faze, {1, 3, 5}) then
  290.                                 vladce.afaze = 11
  291.                             end
  292.                         end,
  293.                     }
  294.                 end,
  295.             }
  296.  
  297.             anim_table[2] = anim_table[1]
  298.             anim_table[3] = anim_table[1]
  299.             anim_table[4] = anim_table[1]
  300.             switch(vladce.ksichty)(anim_table)
  301.  
  302.             vladce.afaze = vladce.afaze - 1
  303.  
  304.             vladce:updateAnim()
  305.         end
  306.     end
  307.  
  308.     -- -------------------------------------------------------------
  309.     local function prog_init_xichtik()
  310.         return function()
  311.             if random(1000) < 5 then
  312.                 xichtik.afaze = random(3)
  313.             end
  314.  
  315.             xichtik:updateAnim()
  316.         end
  317.     end
  318.  
  319.     -- -------------------------------------------------------------
  320.     local function prog_init_chobot()
  321.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  322.  
  323.         chobot.lastdir = dir_no
  324.         chobot.oci = 0
  325.         chobot.chapadla = 0
  326.         chobot.akcnost = 2
  327.  
  328.         return function()
  329.             if chobot.dir ~= dir_no then
  330.                 chobot.akcnost = 7
  331.             elseif chobot.akcnost > 2 and math.mod(game_getCycles(), 5) == 0 then
  332.                 chobot.akcnost = chobot.akcnost - 1
  333.             end
  334.             if chobot.dir ~= chobot.lastdir then
  335.                 if not chobot:isTalking() then
  336.                     if chobot.dir == dir_down then
  337.                         chobot:talk("k1-chob-p", VOLUME_FULL)
  338.                     elseif chobot.dir ~= dir_no then
  339.                         switch(random(3)){
  340.                             [0] = function()
  341.                                 chobot:talk("k1-chob-1", VOLUME_FULL)
  342.                             end,
  343.                             [1] = function()
  344.                                 chobot:talk("k1-chob-2", VOLUME_FULL)
  345.                             end,
  346.                             [2] = function()
  347.                                 chobot:talk("k1-chob-3", VOLUME_FULL)
  348.                             end,
  349.                         }
  350.                     end
  351.                 end
  352.                 chobot.lastdir = chobot.dir
  353.             end
  354.             if chobot.dir == dir_no and math.mod(game_getCycles(), chobot.akcnost) == 0 then
  355.                 if random(2) == 0 then
  356.                     if chobot.chapadla < 2 then
  357.                         chobot.chapadla = chobot.chapadla + 1
  358.                     else
  359.                         chobot.chapadla = 0
  360.                     end
  361.                 else
  362.                     if chobot.chapadla > 0 then
  363.                         chobot.chapadla = chobot.chapadla - 1
  364.                     else
  365.                         chobot.chapadla = 2
  366.                     end
  367.                 end
  368.             end
  369.             pomb1 = xdist(small, chobot) == 0 and ydist(small, chobot) <= 0 and ydist(small, chobot) > -2 or xdist(big, chobot) == 0 and ydist(big, chobot) <= 0 and ydist(big, chobot) > -2
  370.             pomb1 = pomb1 or chobot.dir ~= dir_no
  371.             if pomb1 then
  372.                 chobot.oci = 1
  373.             end
  374.             switch(chobot.oci){
  375.                 [0] = function()
  376.                     if random(100) < 5 then
  377.                         chobot.oci = 2
  378.                     end
  379.                 end,
  380.                 [2] = function()
  381.                     if random(100) < 7 then
  382.                         chobot.oci = 0
  383.                     end
  384.                 end,
  385.                 [1] = function()
  386.                     if not pomb1 and random(100) < 20 then
  387.                         chobot.oci = 0
  388.                     end
  389.                 end,
  390.             }
  391.             chobot.afaze = chobot.oci + 3 * chobot.chapadla
  392.  
  393.             chobot:updateAnim()
  394.         end
  395.     end
  396.  
  397.     -- --------------------
  398.     local update_table = {}
  399.     local subinit
  400.     subinit = prog_init_room()
  401.     if subinit then
  402.         table.insert(update_table, subinit)
  403.     end
  404.     subinit = prog_init_vladce()
  405.     if subinit then
  406.         table.insert(update_table, subinit)
  407.     end
  408.     subinit = prog_init_xichtik()
  409.     if subinit then
  410.         table.insert(update_table, subinit)
  411.     end
  412.     subinit = prog_init_chobot()
  413.     if subinit then
  414.         table.insert(update_table, subinit)
  415.     end
  416.     return update_table
  417. end
  418. local update_table = prog_init()
  419.  
  420.  
  421. -- -----------------------------------------------------------------
  422. -- Update
  423. -- -----------------------------------------------------------------
  424. function prog_update()
  425.     for key, subupdate in pairs(update_table) do
  426.         subupdate()
  427.     end
  428. end
  429.  
  430.